package com.haohuo.question5;

/**
 * 身份证混淆与还原
 */
public class IdEncrypt {

    // 加密和解密只要offset一致即可
    public static final int offset = Integer.MIN_VALUE + 1000;

    // 加密
    public static String encryption(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append("" + (char)(((int)s.charAt(s.length()-i-1)) + offset));
        }
        return sb.toString();
    }

    // 解密
    public static String decryption(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append((char)(((int)s.charAt(s.length()-i-1)) - offset));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String str = "82219920917";
        System.out.println("340"+encryption(str)+"1814");
        System.out.println("340"+decryption(encryption(str))+"1814");
    }
}
